#include "WndForIPC.h"
#include "IIPCWndCallBack.h"

CWndForIPC::CWndForIPC(const std::wstring& strWindowName, bool bRecSameSvrNameMsg)
    : CMsgWindow(strWindowName, bRecSameSvrNameMsg)
    , m_pCallback(NULL)
{
}

CWndForIPC::~CWndForIPC(void)
{
    m_pCallback = NULL;
}

int CWndForIPC::set_handler(IIPCWndCallBack* _p_callback)
{
    m_pCallback = _p_callback;
    return 0;
}

LRESULT CWndForIPC::ProcessWndMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lRet = 0;
    switch (msg)
    {
    case WM_COPYDATA:
    {
        COPYDATASTRUCT* pcopy_data = (COPYDATASTRUCT*)lParam;
        if (pcopy_data)
        {
            if (m_pCallback)
            {
                lRet = m_pCallback->OnProcessCopyData(wParam, pcopy_data);
                break;
            }
        }
        break;
    }
    default:
    {
        if (m_pCallback)
        {
            lRet = m_pCallback->OnProcessIPCMsg(msg, (WPARAM)wParam, (LPARAM)lParam);
        }
        break;
    }
    };
    CMsgWindow::ProcessWndMessage(msg, wParam, lParam);
    return lRet;
}